package org.nstack.network.securitygroup;

import org.springframework.http.HttpMethod;
import org.nstack.header.identity.Action;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.network.l3.L3NetworkVO;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;


@Action(category = SecurityGroupConstant.ACTION_CATEGORY)
@RestRequest(
        path = "/security-groups/{securityGroupUuid}/l3-networks/{l3NetworkUuid}",
        method = HttpMethod.POST,
        responseClass = APIAttachSecurityGroupToL3NetworkEvent.class
)
public class APIAttachSecurityGroupToL3NetworkMsg extends APIMessage {
    @APIParam(resourceType=SecurityGroupVO.class, checkAccount = true, operationTarget = true)
    private String securityGroupUuid;
    @APIParam(resourceType = L3NetworkVO.class)
    private String l3NetworkUuid;
    public String getSecurityGroupUuid() {
        return securityGroupUuid;
    }
    public void setSecurityGroupUuid(String securityGroupUuid) {
        this.securityGroupUuid = securityGroupUuid;
    }
    public String getL3NetworkUuid() {
        return l3NetworkUuid;
    }
    public void setL3NetworkUuid(String l3NetworkUuid) {
        this.l3NetworkUuid = l3NetworkUuid;
    }
 
    public static APIAttachSecurityGroupToL3NetworkMsg __example__() {
        APIAttachSecurityGroupToL3NetworkMsg msg = new APIAttachSecurityGroupToL3NetworkMsg();
        msg.setSecurityGroupUuid(uuid());
        msg.setL3NetworkUuid(uuid());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Attached security group[uuid:%s]",securityGroupUuid).resource(l3NetworkUuid,L3NetworkVO.class.getSimpleName())
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }

}
